<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <% include ../../ejs/_meta.ejs %>
    <title>绑定会员</title>
    <% include ../../ejs/_css.ejs %>
    <link rel="stylesheet" type="text/css" href="../../css/user/binding.css" inline>
</head>

<body class="body-bg" ontouchstart>
<div class="m-page">
    <%-include("../../ejs/_header.ejs", {title: '绑定会员'}) %>
    <section class="m-content">
        <form class="m-form">
            <div class="form-cells">
                <div class="form-cell">
                    <i class="icon-phone"></i>
                    <div class="cell-center">
                        <input type="tel" name="account" id="account" class="cell-input m-input" placeholder="请输入手机号码" required="true" valid="mobile" maxlength="11">
                    </div>
                </div>
                <div class="form-cell cell-code">
                    <i class="icon-code"></i>
                    <div class="cell-center">
                        <input type="tel" name="code" class="cell-input m-input" placeholder="请输入验证码" required="true" maxlength="6">
                    </div>
                    <div class="cell-right m-code">获取验证码</div>
                </div>
            </div>
        </form>
        <div class="m-tip">绑定手机成为我们的会员，享受更多服务！</div>
        <div class="m-btn-box">
            <a href="javascript:;" class="m-btn four" id="submit">确认绑定</a>
        </div>
    </section>
</div>
</body>
<%-include("../../ejs/_js.ejs", {env: env}) %>
<script type="text/javascript">
$(function () {
    //- 获取表单对象
    var $form = $('.m-form');

    //- 获取验证码
    var $code = $('.m-code', $form);
    $code.m_touch(function () {
        //- 移除所有input焦点
        $form.m_form_blur();

        var $this = $(this);
        var $account = $('#account');
        //- 验证手机号码
        if (!$account.m_input_valid()) return false;

        var account = $account.val();

        // 发起ajax请求
        // request({
        //     url: "url",
        //     data: {},
        //     success: function(data){

        //     }
        // });

        // 模拟请求结果
        var message = {result: '1', error: '', data: null}; // 请求结果：成功
        // var message = {result:"0", error:"手机号码已存在", data : null} // 请求结果：失败
        if (message.result == '1') {
            // 请求成功
            $.toast('发送成功，请注意接收');
            $this.countdown();
        } else {
            $.toast(messages.error);
        }
    });

    //- 确认绑定
    var $submit = $('#submit');
    $submit.m_touch(function () {
        if ($form.m_form_valid()) {
            var params = $form.m_form_json();
            // $.post('url', {id: id}, function (data) {

            // });

            // 请求
            var message = {result: '1', error: '', data: null}; // 请求结果：成功
            if (message.result == '1') {
                // 请求成功
                $.toast('手机号码绑定成功', function () {
                    // 绑定成功跳转首页
                    jump.view('home/index.html');
                });
            } else {
                $.toast(message.error);
            }
        }
    });

});
</script>

</html>
